# 使用官方 Python 3.12 镜像作为基础镜像
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/python:3.12-slim

# 设置工作目录
WORKDIR /app

# 配置中国镜像源
RUN rm -rf /etc/apt/sources.list.d/* && \
    echo "deb https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
    echo "deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list

# 安装系统依赖和 git
RUN apt-get update && apt-get install -y \
    git \
    && rm -r /var/lib/apt/lists/*

# 克隆 OpenManus 仓库（包含 requirements.txt 和 config/config.example.toml）
RUN git clone https://github.com/mannaandpoem/OpenManus.git .

# 安装 Python 依赖，通过国内镜像源
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

# 创建 config 目录并复制示例配置文件（如果需要覆盖，可通过 volume 挂载）

RUN cd config && cp config.example.toml config.toml
RUN mkdir -p /home/user
RUN touch /home/user/file.txt
RUN chmod 644 /home/user/file.txt
RUN playwright install
RUN playwright install-deps

# 安装必要的软件包
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    xfce4 xfce4-goodies xorg dbus-x11 x11vnc supervisor && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 创建 VNC 密码文件
RUN mkdir -p /root/.vnc && \
    echo "vncpassword" > /root/.vnc/passwd && \
    x11vnc -storepasswd /root/.vnc/passwd /root/.vnc/passwd && \
    chmod 600 /root/.vnc/passwd

# 创建 supervisord 配置文件
RUN mkdir -p /etc/supervisor/conf.d
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# 暴露 VNC 端口
EXPOSE 5900

# 启动 supervisord
CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/conf.d/supervisord.conf"]